package com.ljh.lottery.controller;

import com.ljh.lottery.common.utils.BeanTransUtil;
import com.ljh.lottery.common.utils.JacksonUtil;
import com.ljh.lottery.pojo.request.CreatePrizeRequest;
import com.ljh.lottery.pojo.request.PageRequest;
import com.ljh.lottery.pojo.response.CommonResult;
import com.ljh.lottery.pojo.response.PrizeListResponse;
import com.ljh.lottery.service.PrizeService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author: Themberfue
 * @date: 2025/4/11 11:08
 * @description:
 */
@RequestMapping("/prize")
@RestController
public class PrizeController {
    private static final Logger log = LoggerFactory.getLogger(PrizeController.class);

    @Resource(name = "prizeServiceImpl")
    PrizeService prizeService;

    /**
     * 创建奖品
     * @param createPrizeRequest 奖品请求
     * @param multipartFile 奖品图片
     * @return 奖品 id
     */
    @PostMapping("/createPrize")
    public CommonResult<Long> createPrize(@Validated @RequestPart("param") CreatePrizeRequest createPrizeRequest,
                                          @RequestParam("prizePic") MultipartFile multipartFile) {
        // TODO 打印日志
        log.info("createPrize createPrizeRequest: {} prizePic: {}", createPrizeRequest, multipartFile.getOriginalFilename());

        return CommonResult.success(
                prizeService.createPrize(createPrizeRequest, multipartFile));
    }

    /**
     * 获得创建的奖品列表
     * @param param 页面参数
     * @return 奖品列表
     */
    @GetMapping("/getPrizePageList")
    public CommonResult<PrizeListResponse> getPrizePageList(PageRequest param) {
        // TODO 打印日志
        log.info("getPrizePageList PageRequest: {}", JacksonUtil.writeValueAsString(param));

        return CommonResult.success(
                BeanTransUtil.transToPrizeListResponse(
                        prizeService.getPrizePageList(param)));
    }

    /**
     * 获取所有创建的奖品列表
     * @return 所有奖品
     */
    @GetMapping("/getAllPrize")
    public CommonResult<PrizeListResponse> getAllPrize() {
        // TODO 打印日志
        log.info("getAllPrize");

        return CommonResult.success(
                BeanTransUtil.transToPrizeListResponse(
                        prizeService.getAllPrize()));
    }
}
